package org.abettor.myinj.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * 配置信息查询类
 * @author abettor
 *
 */
public class Configuration
{
	private static final String CONFIG_FILE_PATH = "conf/conf.properties";
	private Properties prop;
	private static Configuration inst = null;
	private static Object locker = new Object();

	//	私有构造函数
	private Configuration()
	{
		File file = new File(CONFIG_FILE_PATH);
		try
		{
			InputStream is = new FileInputStream(file);
			prop = new Properties();
			prop.load(is);
			is.close();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	/**
	 * 单例模式的获取配置信息对象的方法
	 */
	public static Configuration getInstance()
	{
		synchronized(locker)
		{
			if(inst == null)
			{
				inst = new Configuration();
			}
		}

		return inst;
	}

	/**
	 * 获取配置信息
	 * @param name 属性名称
	 */
	public String getProperty(String name)
	{
		return prop.getProperty(name);
	}
}
